<template>
	<view class="order-operation-warp">
		<view class="button" v-if="orderInfo.status == '11' && orderInfo.payStatus == '0'">
			<u-button type="error" style="width: 120rpx" shape="circle" :size="buttonSize" @click="onDel">删除订单</u-button>
		</view>
		<view class="button" v-if="orderInfo.status == '1' && orderInfo.payStatus == '0'">
			<u-button type="info" style="width: 120rpx" shape="circle" :size="buttonSize" @click="onCancel">取消订单</u-button>
		</view>
		<view class="button" v-if="orderInfo.status == '1' && orderInfo.payStatus == '0'">
			<u-button type="primary" style="width: 120rpx" shape="circle" :size="buttonSize" @click="onPay">立即付款</u-button>
		</view>
		<view class="button" v-if="(orderInfo.status == '3' || orderInfo.status == '4') && orderInfo.deliveryWay == '1'">
			<u-button type="warning" style="width: 120rpx" shape="circle" :size="buttonSize" @click="onLogistics">查看物流</u-button>
		</view>
		<view class="button" v-if="orderInfo.status == '3' && orderInfo.deliveryWay == '1'">
			<u-button type="primary" style="width: 120rpx" shape="circle" :size="buttonSize" @click="onReceiver">确认收货</u-button>
		</view>
		<view class="button" v-if="orderInfo.status == '4' && orderInfo.appraiseStatus == '0'">
			<u-button type="primary" shape="circle" :size="buttonSize" @click="onAppraise">评价</u-button>
		</view>
	</view>
</template>

<script setup lang="ts" name="orderOperation">
import { orderCancel, orderDel, orderReceiver } from '@/api/order/orderInfo';
const emit = defineEmits(['orderCancel', 'orderDel', 'orderReceiver']);
const props = defineProps({
	orderInfo: {
		type: Object,
		default: () => ({}),
	},
	buttonSize: {
		type: String,
		default: 'medium',
	},
});
/**
 * 立即付款
 */
const onPay = () => {
	uni.navigateTo({
		url: '/pages/order/order-pay/index?id=' + props.orderInfo.id,
	});
};
/**
 * 取消订单
 */
const onCancel = () => {
	uni.showModal({
		content: '是否取消订单吗？',
		cancelText: '我再想想',
		success(res) {
			if (res.confirm) {
				let id = props.orderInfo.id;
				orderCancel(id).then((res) => {
					let data = res.data;
					emit('orderCancel', data);
				});
			}
		},
	});
};
/**
 * 删除订单
 */
const onDel = () => {
	uni.showModal({
		content: '是否删除订单吗？',
		cancelText: '我再想想',
		success(res) {
			if (res.confirm) {
				let id = props.orderInfo.id;
				orderDel(id).then((res) => {
					let data = res.data;
					emit('orderDel', data);
				});
			}
		},
	});
};
/**
 * 确认收货
 */
const onReceiver = () => {
	uni.showModal({
		content: '是否确认收货吗？',
		cancelText: '我再想想',
		success(res) {
			if (res.confirm) {
				let id = props.orderInfo.id;
				orderReceiver(id).then((res) => {
					let data = res.data;
					emit('orderReceiver', data);
				});
			}
		},
	});
};
/**
 * 评价
 */
const onAppraise = () => {
	uni.navigateTo({
		url: '/pages/order/order-appraise/index?id=' + props.orderInfo.id,
	});
};
/**
 * 查看物流
 */
const onLogistics = () => {
	uni.navigateTo({
		url: '/pages/order/order-logistics/index?orderId=' + props.orderInfo.id,
	});
};
</script>

<style lang="scss">
.order-operation-warp {
	display: flex;
	align-items: center;
	justify-content: center;

	.button {
		padding-left: 20rpx;
	}
}
</style>
